package com.yixun.qfbao.controller;

import com.yixun.qfbao.api.service.MapService;
import com.yixun.qfbao.model.bmap.BMapGeocodingResult;
import com.yixun.qfbao.request.GenericContentRequest;
import com.yixun.qfbao.response.BaseResponse;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;

@Slf4j
@Controller
@ResponseBody
@RequestMapping("/map")
public class MapController {

    @Autowired
    private MapService mapService;

    @GetMapping(value = "/getBMapInfoByAddress", produces = "application/json")
    public BaseResponse<BMapGeocodingResult> getBMapInfoByAddress(GenericContentRequest request) throws UnsupportedEncodingException {
        BaseResponse<BMapGeocodingResult> response = new BaseResponse<>();
        String address = request.getContent();
        // 本地环境因编码问题需要转换.测试环境、UAT不需要.线上都不需要
        // address = new String(request.getContent().getBytes("ISO-8859-1"),"utf-8");
        BMapGeocodingResult result =  mapService.getBMapInfoByAddress(address);
        response.setData(result);
        response.setCode(ResultEnum.SUCCESS.getNo());
        return response;
    }
}
